<template>
	<view class="coupon-item-wrap">
		<template v-if="false">
			<view class="price-wrap">
				<view class="money-wrap">
					<text class="prefix">￥</text>
					<text class="money-value">{{ record.coupon }}</text>
				</view>
				<view class="coupon-desc" v-if="record.quan_type < 1">
					<text>满{{ record.full_deduction }}元可用</text>
				</view>
			</view>
			<view class="coupon-line">
				<view class="line-inner"></view>
			</view>
			<view class="coupon-info">
				<view class="coupon-name">
					<text>{{ record.title }}</text>
				</view>
				<view class="coupon-time">
					<text v-if="type ===0">有效期{{ record.indate }}天</text>
					<text v-else>{{ record.end_time }}</text>
				</view>
			</view>
			<view v-if="type === 0" class="coupon-btn" :class="{active: record.is_ok}" @click="getCoupon">
				<text>{{ record.is_ok ? '已领取' : '立即领取' }}</text>
			</view>
			<view v-if="type === 1" class="coupon-btn" :class="{active: record.status > 0}" @click="getCoupon">
				<text>{{ record.status <= 0 ? '未使用' : '已使用' }}</text>
			</view>
		</template>
		<div class="images-inner">
			<image class="image" :src="sourceUrl + `/coupon_2.png`" mode="aspectFill"></image>
		</div>
		<div class="coupon_name">
			<text>{{ record.title }}</text>
		</div>
		<div class="coupon_money">
			<text>{{ record.coupon }}</text>
		</div>
		<div class="coupon_btn" v-if="type === 0" @click="getCoupon">
			<text>{{ record.is_ok ? '已领取' : '立即领取' }}</text>
		</div>
		<div class="coupon_btn" v-if="type === 1" @click="getCoupon">
			<text>{{ record.status <= 0 ? '未使用' : '已使用' }}</text>
		</div>
	</view>
</template>

<script>
	export default {
		props: ['type', 'record'],
		methods: {
			getCoupon() {
				if (this.type === 1) return
				if (this.record.is_ok) return
				uni.showModal({
					title: '提示',
					content: '您确定领取吗?',
					success: async ev => {
						if (ev.cancel) return
						const { id } = this.record
						const resp = await this.$request({
							url: "/DiscountCoupon/receiveCoupon",
							data: { id },
						})
						const { code, msg } = resp
						this.$toast({ title: msg })
						if (code !== 1) return
						this.$emit('success', true)
					}
				})

			},
		},
		computed: {},
		data() {
			return {}
		}
	}
</script>

<style lang="scss" scoped>
	.coupon-item-wrap {
		padding: 28rpx 32rpx;
		box-sizing: border-box;
		position: relative;
		display: flex;
		align-items: center;
		background-color: #FFF;
		border-radius: 8rpx;
		overflow: hidden;
		height: 210rpx;

		.coupon_money {
			font-size: 30rpx;
			color: #fff;
			position: absolute;
			left: 350rpx;
		}

		.coupon_btn {
			position: absolute;
			color: #000;
			font-size: 24rpx;
			right: 38rpx;
		}

		.coupon_name {
			position: absolute;
			left: 54rpx;
			top: 78rpx;
			color: #fff;
			font-size: 34rpx;
		}

		.images-inner {
			position: absolute;
			left: 0;
			top: 0;
			right: 0;
			bottom: 0;

			.image {
				width: 100%;
				height: 100%;
			}
		}

		.coupon-line {
			position: absolute;
			left: 240rpx;
			top: 0;
			bottom: 0;
			width: 2rpx;
			box-sizing: border-box;
			padding: 16rpx 0;


			&::after,
			&::before {
				content: "";
				display: block;
				border-radius: 50%;
				overflow: hidden;
				width: 16rpx;
				height: 16rpx;
				background: #F6F7F9;
				position: absolute;
				left: 50%;
				box-shadow: 0 0 12rpx rgba(0, 0, 0, .12);
			}

			&::before {
				top: 0;
				transform: translate(-50%, -50%);
			}

			&::after {
				bottom: 0;
				transform: translate(-50%, 50%);
			}

			.line-inner {
				width: 100%;
				height: 100%;
				border: 1px dashed #FDBAAA;
			}
		}


		.coupon-info {
			margin-left: 68rpx;
			width: 230rpx;

			.coupon-time {
				height: 40rpx;
				font-size: 24rpx;
				color: rgba(0, 0, 0, 0.4);
				line-height: 40rpx;
			}

			.coupon-name {
				height: 48rpx;
				font-size: 28rpx;
				color: #1D2129;
				font-weight: bold;
				line-height: 48rpx;
				white-space: nowrap;
				overflow: hidden;
				text-overflow: ellipsis;
			}
		}

		.price-wrap {
			width: 180rpx;

			.coupon-desc {
				height: 32rpx;
				font-size: 20rpx;
				color: rgba(0, 0, 0, 0.4);
				line-height: 32rpx;
				margin-top: 8rpx;
				text-align: center;
			}

			.money-wrap {
				display: flex;
				flex-flow: row nowrap;
				align-items: flex-end;
				justify-content: center;

				.prefix {
					font-size: 24rpx;
					font-weight: bold;
					color: #FC7655;
					padding-bottom: 8rpx;
				}

				.money-value {
					font-size: 58rpx;
					color: #FC7655;
					font-weight: bold;
				}
			}
		}

		.coupon-btn {
			width: 160rpx;
			height: 56rpx;
			background: linear-gradient(125deg, #FC7655 0%, #FFAC5E 100%);
			border-radius: 100rpx 100rpx 100rpx 100rpx;
			display: flex;
			flex-flow: row nowrap;
			align-items: center;
			justify-content: center;
			font-size: 26rpx;
			color: #FFFFFF;
			margin-left: auto;

			&.active {
				background: #ccc;
			}
		}
	}
</style>